import axios from 'axios';

import type { CardOrderQuery } from '../models/CardOrderList';
import type ChangePassword from '../models/ChangePassword';
import type FeedbackConfig from '../models/Feedback';
import type { RealAuthConfig } from '../models/RealAuth';
import type { TransactionQuery } from '../models/TransactionList';
import type UploadFile from '../models/UploadFile';
import type { UpdateAvatar } from '../models/UploadFile';
import type { WithdrawAccountConfig } from '../models/WithdrawAccount';
import type { WithdrawActionConfig } from '../models/WithdrawAction';
import type { WithdrawQuery } from '../models/WithdrawList';

export const getCardOrderList = (query: CardOrderQuery) => axios.get('/api/v1/cardOrder/list', { params: query.params });

export const getCardOrderDetail = (id: string) => axios.post('/api/v1/cardOrder/detail/list', { customOrderNo: id });

export const getTransactionList = (query: TransactionQuery) => axios.get('/api/v1/flow/user/page', { params: query.params });

export const getUserTotalFlow = () => axios.get('/api/v1/flow/user/total');

export const getWithdrawList = (query: WithdrawQuery) => axios.get('/api/v1/withdrawal/user/page', { params: query.params });

export const getWithdrawAccount = () => axios.get('/api/v1/withdrawal/account');

export const addWithdrawAccount = (query: WithdrawAccountConfig) => axios.post('/api/v1/withdrawal/account', query.body);

export const updateWithdrawAccount = (query: WithdrawAccountConfig) => axios.put('/api/v1/withdrawal/account', query.put);

export const delWithdrawAccount = (id: string) => axios.delete(`/api/v1/withdrawal/account/${id}`);

export const lunchWithdraw = (query: WithdrawActionConfig) => axios.post('/api/v1/withdrawal/apply', query.body);

export const changePassword = (body: ChangePassword) => axios.post('/system/user/profile/update/pwd', body.query);

export const lunchAuth = (body: RealAuthConfig) => axios.post('/api/v1/user/realAuth/initFaceVerify', body.query);

export const getAuthStatus = (certifyId: string) => axios.post(`/api/v1/user/realAuth/describeFaceVerify/${certifyId}`);

export const lunchWxAuth = (body: RealAuthConfig) => axios.post('/api/v1/user/wechat/auth', body.code, { params: body.code });

export const sendFeedBack = (query: FeedbackConfig) => axios.post('api/v1/feedback/add', query.body);

export const getUserBalance = () => axios.post('/api/v1/user/balance');

export const uploadFile = (file: UploadFile) => {
  const formData = new FormData();
  formData.append('file', file.query.file, file.query.file.name);
  return axios.post('/common/upload', file, {
    headers: { 'Content-Type': 'multipart/form-data' },
    data: file,
  });
};

export const updateAvatar = (query: UpdateAvatar) => axios.post('/api/v1/user/edit/avatar', query.body);
